package com.bwlcums.utils;

import java.io.File;
import java.io.IOException;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;

/**
 * 
 * @author lixl
 * 
 */
public class SystemBootstrapListener implements ServletContextListener {

	private Logger logger = Logger.getLogger(getClass());

	public SystemBootstrapListener() {

	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		setSystemStartParams();
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {

	}

	/**
	 * 
	 * @param arg0
	 */
	private static String SYSTEM_PROPERTIES_NAME = "system.properties";

	private void setSystemStartParams() {
		logger.debug("============================");
		logger.debug("=======设置系统启动参数========");
		String classPath = FileUtils.getClassPath();
		try {
			String filepath = classPath + File.separator + "config"
					+ File.separator + SYSTEM_PROPERTIES_NAME;
			logger.debug("=======设置CLASSPTH【" + classPath + "】参数到文件【"
					+ filepath + "】========");
			FileUtils.setPropertiesFileValue(filepath, "classPath",
					classPath);
		} catch (IOException e) {
			e.printStackTrace();
		}
		logger.debug("=======设置完毕========");
	}

}
